package com.heima.wemedia.Thread;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

@Service
public class ThreadPoolService {

    // ThreadPoolTaskExecutor实例，用于执行异步任务
    private final ThreadPoolTaskExecutor taskExecutor;

    /**
     * 构造函数，注入ThreadPoolTaskExecutor实例
     * @param taskExecutor ThreadPoolTaskExecutor实例，用于执行异步任务
     */
    public ThreadPoolService(ThreadPoolTaskExecutor taskExecutor) {
        this.taskExecutor = taskExecutor;
    }

    /**
     * 执行异步任务
     * @param task Runnable任务，表示需要执行的异步任务
     */
    public void executeAsyncTask(Runnable task) {
        taskExecutor.execute(task);
    }
}